package com.notary.tx_live_plugin.platform;

import androidx.annotation.NonNull;

import com.notary.tx_live_plugin.util.TxConstant;
import com.notary.tx_live_plugin.util.PushManager;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * 推流，接收flutter消息处理MethodCallHandler
 */
public class PushMethodCallHandlerImpl implements MethodChannel.MethodCallHandler {
    
    private final PushManager pushManager;
    public PushMethodCallHandlerImpl(PushManager pushManager){
        this.pushManager = pushManager;
    }

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        switch (call.method){
            case TxConstant.PushMethod.startLivePush: //开启直播推流
                result.success(pushManager.startLivePush(call.arguments));
                return;
            case TxConstant.PushMethod.stopLivePush: //结束直播推流
                pushManager.stopLivePush();
                break;
            case TxConstant.PushMethod.onPause: //如果正在录制，暂停直播推流
                pushManager.onPause();
                break;
            case TxConstant.PushMethod.onResume: //如果暂停录制状态，则重新开始直播推流
                pushManager.onResume();
                break;
            case TxConstant.PushMethod.onDestroy:
                pushManager.onDestroy();
                break;
            case TxConstant.PushMethod.isPushRecording: //是否正在录制
                result.success(pushManager.isPushRecording());
                return;
            case TxConstant.PushMethod.turnOnFlashLight: //切换闪光灯
                pushManager.turnOnFlashLight();
                break;
            case TxConstant.PushMethod.isFlashLightOpen: //闪光灯是否开启状态
                result.success(pushManager.isFlashLightOpen());
                return;
            case TxConstant.PushMethod.isFontCamera: //是否是前置摄像头
                result.success(pushManager.isFontCamera());
                return;
            case TxConstant.PushMethod.switchCamera: //切换摄像头
                pushManager.switchCamera();
                break;
            default:
                result.notImplemented();
                return;
        }
        result.success(true);
    }
}
